package packet1;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

public class offer_61 {
    public static void main(String[] args) {
        System.out.println(isStraight1(new int[]{0,0,2,2,5}));
    }
    /*
    输入: [1,2,3,4,5]
输出: True


示例 2:

输入: [0,0,1,2,5]
输出: True
     */
    public static boolean isStraight(int[] nums) {
        Arrays.sort(nums);
        int zeroNum = 0;
        for(int i = 0; i < 5; i++)
        {
            if(nums[i] == 0)
                zeroNum++;
        }
        int b = zeroNum;
        for(int i = b; i < 4; i++)
        {
            if(nums[i + 1] - nums[i] == 1)
            continue;
            else if(nums[i + 1] - nums[i] == 0)
                return false;
            else
            {
                if(nums[i + 1] - nums[i] - 1 <= zeroNum)
                {
                    zeroNum -= (nums[i + 1] - nums[i] - 1);
                }
                else
                    return false;
            }
        }
        return true;
    }
   public static boolean isStraight1(int[]num){
        int max = 0, min = 14;
        Set<Integer> set = new HashSet<>();
        for(int i : num)
        {
            if(i == 0)
                continue;
            max = Math.max(max, i);
            min = Math.min(min, i);
            if(set.contains(i))
                return false;
            else
                set.add(i);


        }
        return max - min < 5;
   }

}
